/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.sql.SQLException;
import java.util.ArrayList;
import modelo.Curso;
import util.Conexao;
import util.Dao;

/**
 *
 * @author bruno
 */
public class CursoDao extends Dao<Curso> {

    public CursoDao() {
        super(new Conexao("Aurea", "sa", "sa", Conexao.sqlServerDriver));
    }

    @Override
    protected Curso novoModelo() {
        return new Curso();
    }

    @Override
    public boolean gravar(Curso modelo) {
        return gravarModelo("INSERT INTO tbCurso(designacao,descricao,fkAreaCientifica)"
                + " VALUES(?,?,?)", modelo);
    }

    @Override
    protected void definirParametrosGravar() throws SQLException {
        conexao.getStatement().setString(1, modelo.getDesignacao());
        conexao.getStatement().setString(2, modelo.getDescricao());
        conexao.getStatement().setInt(3, modelo.getAreaCientifica().getId());
    }

    @Override
    public Curso ler(int id) {
        return lerModelo("SELECT * FROM tbCurso WHERE idCurso = ?", id);
    }

    @Override
    protected void definirParametrosLer() throws SQLException {
        modelo.setDesignacao(conexao.getResultSet().getString("designacao"));
        modelo.setDescricao(conexao.getResultSet().getString("descricao"));
        modelo.setAreaCientifica(new AreaCientificaDao().ler(conexao.getResultSet().getInt("fkAreaCientifica")));
    }

    @Override
    public ArrayList<Curso> lerTodos() {
        return lerTodos("SELECT * FROM tbCurso");
    }
}
